package com.snack.system.controller;

import com.snack.common.core.web.controller.BaseController;
import com.snack.common.core.web.domain.AjaxResult;
import com.snack.common.core.web.page.TableDataInfo;
import com.snack.common.log.annotation.Log;
import com.snack.common.log.enums.BusinessType;
import com.snack.common.security.annotation.RequiresPermissions;
import com.snack.system.domain.TsSpecial;
import com.snack.system.service.ITsSpecialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 今日特价Controller
 * 
 * @author snack
 * @date 2022-09-18
 */
@RestController
@RequestMapping("/special")
public class TsSpecialController extends BaseController
{
    @Autowired
    private ITsSpecialService specialService;

    /**
     * 查询今日特价列表
     */
    @RequiresPermissions("system:special:list")
    @GetMapping("/list")
    public TableDataInfo list(TsSpecial tsSpecial)
    {
        startPage();
        List<TsSpecial> list = specialService.selectList(tsSpecial);
        return getDataTable(list);
    }


    /**
     * 获取今日特价详细信息
     */
    @RequiresPermissions("system:special:query")
    @GetMapping(value = "/{specialId}")
    public AjaxResult getInfo(@PathVariable("specialId") Long specialId)
    {
        return AjaxResult.success(specialService.selectById(specialId));
    }

    /**
     * 新增今日特价
     */
    @RequiresPermissions("system:special:add")
    @Log(title = "今日特价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsSpecial tsSpecial)
    {
        return toAjax(specialService.insert(tsSpecial));
    }

    /**
     * 修改今日特价
     */
    @RequiresPermissions("system:special:edit")
    @Log(title = "今日特价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsSpecial tsSpecial)
    {
        return toAjax(specialService.update(tsSpecial));
    }

    /**
     * 删除今日特价
     */
    @RequiresPermissions("system:special:remove")
    @Log(title = "今日特价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specialIds}")
    public AjaxResult remove(@PathVariable Long[] specialIds)
    {
        return toAjax(specialService.deleteByIds(specialIds));
    }
}
